<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jsp"%>
<html>
<head>
<title>报销出纳支付管理</title>
<link rel="stylesheet" type="text/css" href="${ctx}/styles/ec/ecside_style.css" />
<%@include file="/common/meta.jsp"%>
<%@include file="/common/validator.jsp"%>
<script type="text/javascript">
function showBorrowInfo(id) {
	if (navigator.userAgent.indexOf("MSIE")>0){//IE判断
		var cus=window.showModalDialog("${ctx}/borrow/showIndex.do?borrowerId=" + id, null, "dialogWidth=800px;dialogHeight=555px;resizable: Yes;");
	    if(cus!=null){
	    	var title = document.getElementById("title") ;
	    	title.value=cus.title;
			var borrowId = document.getElementById("borrowId") ;
			borrowId.value=cus.id;
			var borrowAmount = document.getElementById("borrowAmount") ;
			borrowAmount.value=cus.amount;
			var rePayAmount = document.getElementById("rePayAmount") ;
			rePayAmount.value=cus.rePayAmount;			
			
			var noRePayAmount = borrowAmount.value - rePayAmount.value;
			noRePayAmount = Math.round(noRePayAmount*100)/100;
			document.getElementById("noRePayAmount").value = noRePayAmount;	
			
			var amount = document.getElementById("amount").value ;
			
			if (amount <= noRePayAmount) {
				document.getElementById("amount1").value = amount;
			    document.getElementById("offset1").style.display = "";				
			    document.getElementById("offset2").style.display = "none";
			}else {
				document.getElementById("amount1").value = noRePayAmount;
				document.getElementById("amount2").value = amount - noRePayAmount;
				document.getElementById("offset1").style.display = "";
			    document.getElementById("offset2").style.display = "";
			}
			
		}
 	}else{
		window.open("${ctx}/borrow/showIndex.do?borrowerId=" + id,"","width=800px,height=555,menubar=no,toolbar=no,location=no,scrollbars=no,status=no,modal=yes");
		this.returnAction=function(cus){
	    	if(cus!=null){
		    	var title = document.getElementById("title") ;
		    	title.value=cus.title;
				var borrowId = document.getElementById("borrowId") ;
				borrowId.value=cus.id;
				var borrowAmount = document.getElementById("borrowAmount") ;
				borrowAmount.value=cus.amount;
				var rePayAmount = document.getElementById("rePayAmount") ;
				rePayAmount.value=cus.rePayAmount;				
				
				var noRePayAmount = borrowAmount.value - rePayAmount.value;
				noRePayAmount = Math.round(noRePayAmount*100)/100;
				document.getElementById("noRePayAmount").value = noRePayAmount;	
				
				var amount = document.getElementById("amount").value ;
				
				if (amount <= noRePayAmount) {
					document.getElementById("amount1").value = amount;
				    document.getElementById("offset1").style.display = "";				
				    document.getElementById("offset2").style.display = "none";
				}else {
					document.getElementById("amount1").value = noRePayAmount;
					document.getElementById("amount2").value = amount - noRePayAmount;
					document.getElementById("offset1").style.display = "";
				    document.getElementById("offset2").style.display = "";
				}					
	    	}
		};
 	}
}
</script>
</head>
<body>
<div class="x-panel" style="width: 100%">
<div class="x-panel-header">报销支付管理</div>
<div><%@ include file="/common/messages.jsp"%></div>
<div align="center" style="width: 100%">
<s:form action="doPayReimb.do" id="save" method="post">
	<s:hidden name="model.id" />
	<fieldset style="width: 90%; padding:10px 10px 10px 10px;">
	<legend>报销支付编辑</legend>
	<table width="100%" align="left">	
         <tr>
           <td align="right">支付方式：</td>
           <td align="left" width="150" colspan="3">
           		<s:select list='payTypeMap' name="payType" cssStyle="width:100px" headerKey="" headerValue="全部" cssClass="required" ></s:select>
           		<font color="red">*</font>
			</td>				
        </tr>
        
        <tr>
           <td align="right">冲抵借款：</td>
           <td align="left" width="150" colspan="3">
           		<input type="checkbox" id="isOffset" name="isOffset"  style="border: 0" onclick="selectBorrow()">
			</td>				
        </tr>
               
                   
        <tr id="borrowInfo">
           <td align="right">借款信息：</td>        
           <td colspan="3">
           <table cellpadding="0" cellspacing="0">
               <tr>
                 <td>
                   <a href="#" onclick="showBorrowInfo(${model.reimb.reimber.id})" class="button" title="弹出的借款单列表中,双击某一行可确定其借款信息">选择借款单</a>
                   &nbsp;【注:查询该报销人所有的未清帐的借款单信息！】
                 </td>
               </tr>
               <tr>
                 <td style="border-color:#CBCBCB; BORDER-top:1px dotted; BORDER-bottom:1px dotted; BORDER-left:1px dotted; BORDER-right:1px dotted">
                                                借款标题：<input type="text" id="title" style="width:330px;color:#808080;border: 0">
                           <input type="hidden" id="borrowId" name="borrowId"/>
                  </td>
               </tr>
	           <tr>
                 <td style="border-color:#CBCBCB; BORDER-bottom:1px dotted; BORDER-left:1px dotted; BORDER-right:1px dotted">
		                                      借款金额：<input type="text" id="borrowAmount" readonly="readonly" style="width:75px;color:#808080;border: 0">
		                                      还款金额：<input type="text" id="rePayAmount" readonly="readonly" style="width:75px;color:#808080;border: 0">  	                                      
		                                      未还金额：<input type="text" id="noRePayAmount" readonly="readonly" style="width:75px;color:#808080;border: 0"> 		                                           
		         </td>
			   </tr>
		   </table>
		   </td>				
        </tr>
        <tr>
           <td align="right">报销金额：</td>
           <td align="left" width="80">
           		<s:textfield id="amount" name="model.reimb.amount" cssStyle="width:80px;border:0" readonly="true"></s:textfield >
		   </td>
           <td colspan="1" width="465"> 
           <div style="width: 500px;">
	           <div id="offset1" style="float: left; width: 190px;display: none">       		
	      		 <font color="green">
	      		 注：冲抵借款【<input id="amount1" name="amount1" type="text" readonly="readonly" style="width:75px;text-align: center;border: 0">】</font>
	      		</div>
	      		<div id="offset2" style="float: left;width: 290px;display: none">    
	      		 <font color="red">
	      		           支付金额【<input id="amount2" type="text" readonly="readonly" style="width:75px;text-align: center;border: 0">】</font>
	      		</div>
      		</div>
      		</td>
      		<td></td>
        </tr>
		<tr>
			<td align="right">备&nbsp;&nbsp;&nbsp;&nbsp;注：</td>
			<td align="left" colspan="3">
				<textarea id="descn" name="model.descn" style="width: 450px;" rows="4" >${model.descn}</textarea>
			</td>
		</tr>
        	

	</table>
	</fieldset>
	<table width="600px" style="margin-bottom: 10px;">
		<tr>
			<td style="text-align: center;">
			  <s:submit value="保存" cssClass="button" onclick="return doPayReimb()"/> 
			  &nbsp;&nbsp;
              <input type="button" value="返回" onclick="history.go(-1)" class="button"/>
			</td>
		</tr>
	</table>
</s:form>
</div>
</div>

<script type="text/javascript">

$(document).ready(function() {
	document.getElementById("borrowInfo").style.display = "none";
	$("#save").validate();
});


function selectBorrow() {
	var isOffset = document.getElementById("isOffset");
	if (isOffset.checked) {
		document.getElementById("borrowInfo").style.display = "";
	}else {
		document.getElementById("borrowInfo").style.display = "none";
		document.getElementById("offset1").style.display = "none";
	    document.getElementById("offset2").style.display = "none";
		document.getElementById("title").value="";
		document.getElementById("borrowId").value="";
		document.getElementById("borrowAmount").value="";
		document.getElementById("rePayAmount").value="";
		document.getElementById("offsetAmount").value="";		
		document.getElementById("noRePayAmount").value="";
		document.getElementById("amount1").value="";
		document.getElementById("amount2").value="";
		
	}
	
}

function doPayReimb() {
	var isOffset = document.getElementById("isOffset");
	if (isOffset.checked) {
		var borrowId = document.getElementById("borrowId").value;
		if (borrowId == null || borrowId =="") {
			alert("请您选择借款单！");
			return false;
		}
	}
	if (confirm("您确认要支付此报销申请单吗？")){
		return true;
	}else {
		return false;
	}
}
</script>
</body>
</html>